package cn.ljy.authority.web.controller.backstage.system.dict;


import cn.ljy.authority.model.SysDictItem;
import cn.ljy.authority.model.query.SysDictItemQuery;
import cn.ljy.authority.service.SysDictItemService;
import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.model.result.ResponseData;
import cn.ljy.common.model.validate.AddWorkValidation;
import cn.ljy.common.model.validate.UpdateWorkValidation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

@Api(tags = "后台数据字典列表管理模块")
@RestController
@RequestMapping(value = "/backstage/system/dict/item")
public class SysDictItemController extends BaseBackstageController<SysDictItem, SysDictItemQuery,String> {

    @Autowired
    private SysDictItemService sysDictItemService;

    @Override
    public String getAuthorityPrefix() {
        return "sys:dictItem"; // 定义模块权限前缀
    }

    //网站基本功能，去掉查询权限要求
    @GetMapping("/all")
    @PreAuthorize("permitAll()")
    @Override
    public ResponseData query(SysDictItemQuery query){
        return super.query(query);
    }

    @PreAuthorize("permitAll()")
    @Override
    protected ResponseData query(Integer page, Integer pageSize, SysDictItemQuery query) {
        return super.query(page, pageSize, query);
    }

    @ApiOperation(value = "批量删除指定的多个字典列表")
    @PreAuthorize("hasAuthority('sys:dictItem:del')")
    @Override
    public ResponseData deletes(@NotEmpty(message="请选择要移除的记录")String[] ids){
        return super.deletes(ids);
    }

    @ApiOperation(value = "编辑字典列表")
    @PreAuthorize("hasAuthority('sys:dictItem:edit')")
    @Override
    public ResponseData edit(@Validated({UpdateWorkValidation.class}) @RequestBody SysDictItem sysDictItem){
        return super.edit(sysDictItem);
    }

    @ApiOperation(value = "添加字典列表")
    @PreAuthorize("hasAuthority('sys:dictItem:add')")
    @Override
    protected ResponseData add(@Validated({AddWorkValidation.class}) @RequestBody SysDictItem sysDictItem) {
       return super.add(sysDictItem);
    }


    //=========================扩展部分=============================================//
}
